# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: NOGISAKA Sadata <ngsksdt@gmail.com>
# Contributor: Bennett Piater <bennett at piater dot name>

pkgname=doctl
pkgver=1.100.0
pkgrel=1
pkgdesc='The official command line interface for the DigitalOcean API'
url='https://github.com/digitalocean/doctl'
arch=('loong64' 'x86_64')
license=('Apache')
depends=('glibc')
makedepends=('go')
source=(https://github.com/digitalocean/${pkgname}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('55dde45acf11c6569e7c949a3573d8cedf074aee460096cb97195465ebbf509ce4a21b69f76067acc45a641c87bfd1b56e8513de3f574246f8a4a85911d79c79')
b2sums=('42f804c6d32998102ea7e82ab85c1653dc835d920f754160365d19666bb560930d8e1df88c0428c1e8842448660b4262dd2a7de2c0515a5720d7fe3e4e4dc37f')

build() {
  cd ${pkgname}-${pkgver}
  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"
      -X github.com/digitalocean/doctl.Major=$(echo $pkgver | cut -d. -f1)
      -X github.com/digitalocean/doctl.Minor=$(echo $pkgver | cut -d. -f2)
      -X github.com/digitalocean/doctl.Patch=$(echo $pkgver | cut -d. -f3)
      -X github.com/digitalocean/doctl.Label=release
    " \
    ./cmd/...
}

check() {
  cd ${pkgname}-${pkgver}
  ./doctl --help
}

package() {
  cd ${pkgname}-${pkgver}
  install -Dm 755 "${pkgname}" -t "${pkgdir}/usr/bin"

  # setup completions
  install -dm 755 "${pkgdir}/usr/share/bash-completion/completions" \
                  "${pkgdir}/usr/share/zsh/site-functions" \
                 "${pkgdir}/usr/share/fish/vendor_completions.d"
  "${pkgdir}/usr/bin/${pkgname}" completion bash > "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"
  "${pkgdir}/usr/bin/${pkgname}" completion zsh > "${pkgdir}/usr/share/zsh/site-functions/_${pkgname}"
  "${pkgdir}/usr/bin/${pkgname}" completion fish > "${pkgdir}/usr/share/fish/vendor_completions.d/${pkgname}.fish"
}

# vim: ts=2 sw=2 et:
